import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;

/*
   一个整数数组划分为k个区间，钥匙的区间至少出现一个的数之和的总和最大，输出该最大值
 */
public class test2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNextInt()) {
            int n = sc.nextInt();
            int k = sc.nextInt();
            int[] arr = new int[n];
            for(int i=0;i<n;i++) {
                arr[i] = sc.nextInt();
            }

            int result = maxUniqueSum(arr, n, k);
            System.out.println(result);

        }
    }

    public static int maxUniqueSum(int[] nums, int n, int k) {
        if (k > n)  return 0;

        int[][] dp = new int[n+1][k+1];

        //遍历每个区间
        for(int j=1;j<=k;j++) {
            for(int i=j;i<=n;i++) {
                dp[i][j] = 0;

                HashSet<Integer> uniqueSet = new HashSet<>();
                HashMap<Integer, Integer> freqMap = new HashMap<>();
                int uniqueSum = 0;

                for(int p=i;p>=j;p--) {
                    int current = nums[p-1];
                    freqMap.put(current, freqMap.getOrDefault(current, 0)+1);

                    if (freqMap.get(current) == 1) {
                        uniqueSet.add(current);
                        uniqueSum += current;
                    } else if (freqMap.get(current) == 1) {
                        uniqueSet.remove(current);
                        uniqueSum -= current;
                    }

                    dp[i][j] = Math.max(dp[i][j], dp[p-1][j-1] + uniqueSum);

                }
            }
        }

        return dp[n][k];
    }
}
